#!/bin/sh
#这个脚本是为了收集云服务器健康指标数据
#cpu的数据
while true
do
cpuUsage=`top -bn 1| grep load | awk '{printf "\"cpuUsage\":%.2f", $(NF-2)}'`
#内存的数据
memoryUsage=`free -m| awk 'NR==2 {printf "\"memoryUsage\":%.2f", $3/$2*100}'`
#硬盘的数据
diskUsage=`df -h| grep -w "/"| awk '{printf $(NF-1)}'| awk -F"%" '{printf "\"diskUsage\":" $1}'`
#服务器的ip地址
serverIp=`hostname -I| awk '{printf "\"serverIp\":"  "\"" $1 "\""}'`
#创建时间
createTime=`date +"\"createTime\"":"\"%Y-%m-%d %H:%M:%S\""`
#发送http请求
curl -H "Content-Type: application/json" -X POST -d "{$cpuUsage,$memoryUsage,$diskUsage,$serverIp,$createTime}" "http://192.168.145.1:8080/status/add_status"
sleep 10
done
